package com.itheima.controller;

import com.itheima.pojo.Dept;
import com.itheima.pojo.Result;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RequestMapping("/depts")
@RestController
public class DeptController {
    @Autowired
    private DeptService deptService;

    @GetMapping
    public Result selectAll(){
        List<Dept> depts = deptService.selectAll();
        return Result.success(depts);
    }

    @DeleteMapping
    public Result deleteDept( Integer id){
        deptService.deleteDept(id);
        return Result.success();
    }

    @PostMapping
    public Result insertDept( @RequestBody Dept dept){
        deptService.insertDept(dept);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result selectDept(@PathVariable Integer id){
        Dept dept =  deptService.selectDept(id);
        return Result.success(dept);
    }

    @PutMapping
    public Result updateDept(@RequestBody Dept dept){
        deptService.updateDept(dept);
        return Result.success();
    }


}
